<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑图书 - 图书借阅系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .form-container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="/admin/dashboard">
                <i class="fas fa-cogs"></i> 管理后台
            </a>
            <div class="navbar-nav ms-auto">
                <span class="navbar-text me-3">
                    管理员
                </span>
                <a class="nav-link" href="/admin/logout">退出登录</a>
            </div>
        </div>
    </nav>

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="form-container">
                    <h2>编辑图书信息</h2>
                    <hr>
                    
                    <c:if test="${not empty error}">
                        <div class="alert alert-danger">${error}</div>
                    </c:if>
                    
                    <c:if test="${not empty success}">
                        <div class="alert alert-success">${success}</div>
                    </c:if>
                    
                    <form action="/book/update" method="post">
                        <input type="hidden" name="id" value="${book.id}">
                        
                        <div class="mb-3">
                            <label for="title" class="form-label">书名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="title" name="title" value="${book.title}" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="author" class="form-label">作者 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="author" name="author" value="${book.author}" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="isbn" class="form-label">ISBN <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="isbn" name="isbn" value="${book.isbn}" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="publisher" class="form-label">出版社</label>
                            <input type="text" class="form-control" id="publisher" name="publisher" value="${book.publisher}">
                        </div>
                        
                        <div class="mb-3">
                            <label for="publishDate" class="form-label">出版日期</label>
                            <input type="date" class="form-control" id="publishDate" name="publishDate" value="${book.publishDate}">
                        </div>
                        
                        <div class="mb-3">
                            <label for="categoryId" class="form-label">分类 <span class="text-danger">*</span></label>
                            <select class="form-select" id="categoryId" name="categoryId" required>
                                <option value="1" ${book.categoryId == 1 ? 'selected' : ''}>文学</option>
                                <option value="2" ${book.categoryId == 2 ? 'selected' : ''}>科技</option>
                                <option value="3" ${book.categoryId == 3 ? 'selected' : ''}>历史</option>
                                <option value="4" ${book.categoryId == 4 ? 'selected' : ''}>教育</option>
                                <option value="5" ${book.categoryId == 5 ? 'selected' : ''}>艺术</option>
                            </select>
                        </div>
                        
                        <div class="mb-3">
                            <label for="totalQuantity" class="form-label">总数量 <span class="text-danger">*</span></label>
                            <input type="number" class="form-control" id="totalQuantity" name="totalQuantity" value="${book.totalQuantity}" min="1" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="description" class="form-label">图书简介</label>
                            <textarea class="form-control" id="description" name="description" rows="4">${book.description}</textarea>
                        </div>
                        
                        <div class="d-flex justify-content-between">
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save"></i> 保存修改
                            </button>
                            <a href="/admin/books" class="btn btn-secondary">
                                <i class="fas fa-arrow-left"></i> 返回列表
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/js/bootstrap.bundle.min.js"></script>
</body>
</html>